define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";

	
	var myScrollTop=0;
	window.onscroll=function(){	
		function get_scrollTop_of_body(){ //scrollTop能力检测函数
					var scrollTop; 
					if(typeof window.pageYOffset != 'undefined'){ 
					scrollTop = window.pageYOffset; 
					} 
					else 
					if(typeof document.compatMode != 'undefined' && 
					document.compatMode != 'BackCompat'){ 
					scrollTop = document.documentElement.scrollTop; 
					} 
					else 
					if(typeof document.body != 'undefined'){ 
					scrollTop = document.body.scrollTop; 
					} 
					return scrollTop; 
		}
		myScrollTop = parseInt(get_scrollTop_of_body());//获取ScrollTop的值
	};
	
	
	// 返回顶部
    var $backToTopTxt = "返回顶部", 
		$backToTopEle = $('<div class="backToTop"></div>').appendTo($("body"))
        .attr("title", $backToTopTxt).click(function() {
            $("html, body").animate({ scrollTop: 0 }, 1000);
    	}),
	    $backToTopFun = function() {
        var st = $(document).scrollTop(),
	    winh = $(window).height();
        (st > 10)? $backToTopEle.show(): $backToTopEle.hide();    
    };
    $(window).bind("scroll", $backToTopFun);	
	$(".backToTop").hover(function(){
    	$(this).stop().fadeTo("fast",1);
    },function(){
		$(this).stop().fadeTo("fast",0.6);
   });
   $backToTopFun();
	
	//店铺/商品切换
	$(document).on("mouseover",".selectbox span",function(){
		$(this).parent().find("ul").show();
	})
	.on("mouseleave",".selectbox",function(){
		$(this).find("ul").hide();
	});
	

	
	//切换城市
	$(document).on("click","#ldh-city .ldh-ctLabel",function(event){
		if(!$("#ldh-city").hasClass("on")){
			$("#ldh-city").addClass("on");						
		}else{$("#ldh-city").removeClass("on");}
	});	
	$(document).on("click",".ldh-location",function(event){
		var _target=$(event.target).parents();
		if(!_target.hasClass("ldh-city")){
			  $("#ldh-city").removeClass("on");						  
		}					
	});	
	
	//历史地址显示/消失
	$(document).on("mouseover",".ldh-indAddress",function(){
		$(this).parent().find(".ldh-addressHistory").show();
	})
	.on("mouseleave",".ldh-indexAddress",function(){
		$(this).find(".ldh-addressHistory").hide();
	})
	.on("click",".ldh-addressHistory li",function(){
		$(this).parents(".ldh-addressHistory").hide();
	});
	
	//回车登录
	$(document).on("keydown",function(event){	
		event=window.event||event;
		var currkey=event.keyCode||event.which||event.charCode;			
		
		if(currkey==13){
			
			if(!$("#ldh-loginDiv").is(":hidden")){
				
				exports.login();
				
			}else if(!$("#ldh-register").is(":hidden")){
				
				exports.register();
				
			}else if(exports.getFromPage()=="shopIndex"){
				
				if(validate.isNull($("#merchandiseName").val())){
					return;
				}
				
				$ldh_shop.searchMerchandise();
				
			}else if(exports.getFromPage()=="index" || exports.getFromPage()=="shopList"){
				
				if(validate.isNull($("#inputSearch").val())){
					return;
				}
				
				$ldh_base.search();
				
			}
			
			
			return false;
		}
		
	});
		
	require("../../custom/base/component-core.js");
	
	var async = require("../../custom/base/component-async.js");
	
	var validate = require("../../custom/base/component-validate.js");
		
	require("../../custom/base/component-md5.js");
	
	
	exports.init=function(m) {
		
		window.$ldh_base = m;
		
	
	};
	
	//截取字符串,超出长度用省略号表示
	exports.subString=function(value,length){
		
		if(value.length>=length){
			
			value=value.substring(0,length)+"...";
			
		}
		
		return value;
		
	};
	
	//替换
	exports.replaceQuotationMarks=function(str)
	{
	    var regex = new RegExp(" ", "g");
	    return str.replace(regex, "");
	};
	
	//保存cookie
	exports.setCookie=function(key,value){
		   if(document.URL.indexOf("storeme.cn")>=0){
		    	
			   $.cookie(key,value, {expires:30,path:'/',domain: ".storeme.cn"});
			 
		   }else if(document.URL.indexOf("jujie.xyz")>=0){
		    	
				 $.cookie(key,value, {expires:30,path:'/',domain: ".jujie.xyz"});
				 
		   }else{
			   
			   $.cookie(key,value, {expires:30,path:'/'});
			 
		   }
		//$.cookie(key,value, {expires:30,path:'/'});
	};
	
	//获取cookie
	exports.getCookie=function(key){
		
		if(key=="lng"){
			
			return $.cookie(key)==null?"113.355747":$.cookie(key);
		}else if(key=="lat"){
			
			return $.cookie(key)==null?"23.127191":$.cookie(key);
		}else{
			
			return $.cookie(key)==null?"":$.cookie(key);
		}
		
	};
	
	//清除cookie
	exports.clearCookie=function(key){
		
		$.cookie(key, null, {
			path : '/'
		});
	};
	
	//显示完整的图片
	exports.ResizeImage=function(id) {

	var img = document.getElementById(id);
	if(img == null){
		return;
	}
	
	


	var widthHeightRate = img.width / img.height;

		if (widthHeightRate >1) {
		
		img.width = (img.width > 234) ? "234" : img.width;
		
		img.height = img.width / widthHeightRate;
		
		
		} else {
		img.height = (img.height > 234) ? "234" : img.height;
		img.width = img.height * widthHeightRate;
		
		}


	};
	
	//验证登录状态
	exports.validateLoginStatus=function(data){
		
		if(data.code == "-9999999999"){
			exports.loginShow();
			return false;
		}
		
		return true;
	};
	
	//通过用户代码验证登录状态
	exports.validateLoginStatusByUserId=function(fun){
		var userId=$("#session_userid").val();
		if(validate.isNull(userId)){
			exports.loginShow(fun);
			return false;
		}
		return true;
	};
	
	//获取滚动高度
	exports.getMyScrollTop=function(){
		
		return myScrollTop;
	};
	
	//等待加载
	exports.showLoading=function(divId,height,isClear){
		
			if(height=="" || typeof(height) == "undefined" ){
				height=200;
			}
			
			if(isClear){
				$(divId).html("");
			}
			
			var waiting='<div class="ldh-waiting" style="height:'+height+'px"></div>';
			
			$(divId).append(waiting);
	};
	//设置页面来源
	exports.setFromPage=function(fromPage){
		
		this.fromPage=fromPage;
		
	};
	
	//获取页面来源
	exports.getFromPage=function(){
		
		return this.fromPage;
		
	};
	
	//移除加载
	exports.cancelLoading=function(divId){		
			$(divId).find(".ldh-waiting").remove();
	};
	
	//关闭登录等
	exports.closeDialog=function(){
		
		alert("关闭登录框");
		
	};
	
	//个人中心
	exports.ucenter=function(){
		
		get2post(ctx+"/v1/pages/ucenter/ucenter.jsp","_blank");
		
	};
	
	//切换账户
	exports.changeAccount=function(){
		
		exports.loginShow();
		
	};
	
	//退出登录
	exports.logout=function(){
		
		eval(Wind.compile("async", function() {

			var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Login/logout.do", ""));
			//清理session
			$("#session_userid").val("");
			$("#session_username").val("");
			$("#session_iconurl").val("");
			$("#session_shopid").val("");
			$("#session_agentId").val("");

			exports.noLoginShow();
			
		}))().start();
						
	};
	
	//设置准备执行的方法
	exports.setFunction=function(fun){
		
		if(!validate.isNull(fun)){
			
			this.fun=fun;
			
		}
		
	};
	
	//获取准备执行的方法
	exports.getFunction=function(){
		
		return this.fun;
		
	};
	
	//登录后自动执行某个方法
	exports.autoFunction=function(){
		
		
		if(validate.isNull(exports.getFunction()))
			return;
		
		if(exports.getFunction()=="ucenter_order"){

			get2post(ctx+"/v1/pages/ucenter/ucenter.jsp?tag=order");
			
		}else if(exports.getFunction()=="ucenter_favor"){
			
			get2post(ctx+"/v1/pages/ucenter/ucenter.jsp?tag=favor");
			
		}else if(exports.getFunction()=="openStore"){
			
		
			exports.gotoOpenStore("openStore");
			
		}
		
	};

	//登录框出现
	exports.loginShow=function(fun){	
		$(".ldh-loginBox").show();
		var login_h=$("#ldh-loginDiv").outerHeight();
		$("#ldh-loginDiv").css("top",-login_h);
		$("#ldh-loginDiv").show().siblings(".ldh-loginDiv").hide();	
		$("#ldh-loginDiv").animate({top:230},300);	
		$("#login_mobile").focus();
		exports.loginDivHide();	
		
		exports.setFunction(fun);
		
		
	};
	
	//登录框消失
	exports.loginDivHide=function(){
		$(document).on("click",".ldh-loginBox",function(event){
			var _target=$(event.target).parents();
			if(!_target.hasClass("ldh-loginBox")){
				var win_height=$(window).height();
				$("#ldh-loginDiv").animate({top:win_height},300);	
				setTimeout(function(){$(".ldh-loginBox").hide();$("#ldh-loginDiv").stop(true,true)},300);
			}
		})
	};

	//登录
	exports.login=function(){

		var mobile=$("#login_mobile").val();
				
		var password=$("#login_password").val();
		
		if(!validate.isMobile(mobile)){
			
			$("#tip_login").html("请填写正确的手机号码");
			
			return;
		}
		
		if(validate.isNull(password)){
			
			$("#tip_login").html("请输入登录密码");
			
			return;
		}

		if("123456" == password || "000000"== password || "111111"== password){
			alert("密码过于简单，请登录后马上修改密码！");
		}
		
		$("#tip_login").html("");
		
		var params={
				
			"userName":mobile,
			
			"password":MD5(password)
			
		};
		
		exports.showLoading("#btn_login",25,true);
		
		eval(Wind.compile("async", function() {

			var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Login/login.do", params));

			if(data.code =="1"){
				//登录成功
			
				$(".ldh-loginBox").hide();
				
				exports.hasLoginShow(data["userId"],data["userName"],data["iconUrl"]);
					
				$("#session_shopid").val(data["shopId"]);
				
				$("#session_agentId").val(data["agentId"]);
				
				exports.getIsOpenShop($("#session_shopid").val());
				
				exports.getIsShowAgent($("#session_agentId").val());
				
				exports.autoFunction();
				
			}else{
				
				$("#tip_login").html(data.message);
				
			}
			
			$("#btn_login").html("登录");
			
		}))().start();
		
	};
	

	//未登录的显示
	exports.noLoginShow=function(){
		
		
		if(exports.getFromPage()=="index"){
			
			$("#div_login").show();
			
			$("#div_user").hide();
			
			$("#div_logout").hide();
			
			$("#ul_has_ucenter").hide();
			
			$("#ul_no_ucenter").show();
			
			$("#session_userid").val("");
			
			$("#session_username").val("");
			
			$("#session_shopid").val("");
			
			exports.showOpenStore();
			
		}else if(exports.getFromPage()=="shopIndex"){
			
			$("#p_login").show();
			
			$("#p_user").hide();
			
			$("#user_box").hide();
			
			$ldh_shop.getShopDetail($ldh_shop.getShopId());
		
			$ldh_cart.getCartNum();
			
			if($("#ldh-cart").hasClass("on")){
				
				$("#ldh-cart").removeClass("on");
			}
			
		}else if(exports.getFromPage()=="merchandiseList"){
			
			$("#p_login").show();
			
			$("#p_user").hide();
			
			$("#user_box").hide();

			$ldh_cart.getCartNum();
			
			if($("#ldh-cart").hasClass("on")){
				
				$("#ldh-cart").removeClass("on");
			}
			
		}else if(exports.getFromPage()=="shopList"){
			
			$("#div_login").show();
			
			$("#div_user").hide();
			
			$("#div_logout").hide();
			
			$("#ul_has_ucenter").hide();
			
			$("#ul_no_ucenter").show();
			
			$("#session_userid").val("");
			
			$("#session_username").val("");
			
			$("#session_shopid").val("");
			
			$("#session_agentId").val("");
			
			exports.showOpenStore();
			
			$("#userName").html("登录");
			
		}else if(exports.getFromPage()=="userIndex"){
			
			get2post(ctx+"/v1/pages/index.jsp");
			
		}else if(exports.getFromPage()=="subOrder" || exports.getFromPage()=="openStore" || exports.getFromPage()=="common"){
			
			$("#p_login").show();
			
			$("#p_user").hide();
			
			$("#user_box").hide();
			
			
		}
		
		$("#iconUrl").attr("src",ctx+"/v1/img/category_f.png");
		
		//清空input
		$("#login_password").val("");
		$("#login_mobile").val("");
		$("#password").val("");
		$("#mobile").val("");
		
		
	};
	
	//已登录的显示
	exports.hasLoginShow=function(userId,userName,iconUrl){
		
		$("#session_userid").val(userId);
		
		$("#session_username").val(userName);
		
		$("#session_iconurl").val(iconUrl);
				
		if(validate.isNull(iconUrl)){
			
			iconUrl=ctx+"/v1/img/category_f.png";
			
		}else{
			
			iconUrl=fileOpenUrl+iconUrl;
		
		}
		
		$("#iconUrl").attr("src",iconUrl);
		
		if(exports.getFromPage()=="index"){
			
			$("#div_login").hide();
			
			$("#div_user").show();
			
			$("#div_logout").show();
			
			$("#ul_has_ucenter").show();
			
			$("#ul_no_ucenter").hide();
			
			$("#div_user").html('<span onClick="">'+userName+'</span>');
			
			
			
		}else if(exports.getFromPage()=="shopIndex"){
			
			$("#p_login").hide();
			
			$("#p_user").show();
			
			$("#user_box").show();
			
			$("#userName").html(userName);
			
			$ldh_shop.getShopDetail($ldh_shop.getShopId());
			
			
			//alert($ldh_cart);
			
			$ldh_cart.getCartNum();
			
			if($("#ldh-cart").hasClass("on")){
				$ldh_cart.getCartList();
			}
			
		}else if(exports.getFromPage()=="merchandiseList"){
			
			$("#p_login").hide();
			
			$("#p_user").show();
			
			$("#user_box").show();
			
			$("#userName").html(userName);
			
			$ldh_cart.getCartNum();
			
			if($("#ldh-cart").hasClass("on")){
				$ldh_cart.getCartList();
			}
			
		}else if(exports.getFromPage()=="shopList"){
			
			
			$("#div_login").hide();
			
			$("#div_user").show();
			
			$("#div_logout").show();
			
			$("#ul_has_ucenter").show();
			
			$("#ul_no_ucenter").hide();
			
			$("#div_user").html('<span onClick="">'+userName+'</span>');
			
			$("#userName").html(userName);
			
			$("#shoplist_iconUrl").attr("src",iconUrl);
			
		}else if(exports.getFromPage()=="userIndex"){
			
			$("#p_login").hide();
			
			$("#p_user").show();
			
			$("#user_box").show();
			
			$("#userName,#userIndex_userName").html(userName);
			
			$("#userIndex_iconUrl").attr("src",iconUrl);
			
		
			
			if($("#tag").val()=="favor"){
				
				
				$(".ldh-index-clobiz").css("color","#ed5d3a");
				
				$ldh_user.getMyFavorShop();
				
			}else{
				
				$(".ldh-index-myorder").css("color","#ed5d3a");
				
				$ldh_user.getMyOrder();
			}
			
			exports.getIsOpenShop($("#session_shopid").val());
			
			exports.getIsShowAgent($("#session_agentId").val());
			
		}else if(exports.getFromPage()=="subOrder" || exports.getFromPage()=="openStore" || exports.getFromPage()=="common"){
			
			$("#p_login").hide();
			
			$("#p_user").show();
			
			$("#user_box").show();
			
			$("#userName").html(userName);
			
		}
		
		
	};
	
	
	//注册框出现
	exports.registerShow=function(){	
		
		$(".ldh-loginBox").show();
		var register_h=$("#ldh-register").outerHeight();
		$("#ldh-register").css("top",-register_h);
		$("#ldh-register").show().siblings(".ldh-loginDiv").hide();	
		$("#ldh-register").animate({top:230},300);	
		exports.registerHide();	
	};
	
	//注册框消失
	exports.registerHide=function(){
		$(document).on("click",".ldh-loginBox",function(event){
			var _target=$(event.target).parents();
			if(!_target.hasClass("ldh-loginBox")){
				var win_height=$(window).height();
				$("#ldh-register").animate({top:win_height},300);	
				setTimeout(function(){$(".ldh-loginBox").hide();$("#ldh-register").stop(true,true)},300);	
			}		
		})
	};
	
	//同意注册协议
	exports.agree=function(obj){
		
		if($(obj).hasClass("checked")){
			
			$(obj).removeClass("checked");
			
			$("#cb_agree").val("0");
			
		}else{
			
			$(obj).addClass("checked");
			
			$("#cb_agree").val("1");
		}
				
	};
	
	//注册
	exports.register=function(){

		var mobile=$("#mobile").val();
		
		var validateCode=$("#validateCode").val();
		
		var password=$("#password").val();
		
		if(!validate.isMobile(mobile)){
			
			$("#tip_register").html("请填写正确的手机号码");
			
			return;
		}
		
		if(validate.isNull(validateCode)){
			
			$("#tip_register").html("请输入短信验证码");
			
			return;
		}

		if(!validate.isLoginPassword(password)){
			
			$("#tip_register").html("密码必须为6-20位数字，字母，符号组合");
			
			return;
		}
		
		if($("#cb_agree").val()!="1"){
			
			$("#tip_register").html("请勾选《云便利商店注册协议》");
			
			return;
		}
		
		$("#tip_register").html("");
		
		var params={
				
			"mobile":mobile,
			
			"validateCode":validateCode,
			
			"password":MD5(password)
			
		};
		
		exports.showLoading("#btn_register",20,true);
		
		eval(Wind.compile("async", function() {

			var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Reg/register.do", params));

			if(data.code =="1"){
				//注册成功,自动登录
				$("#mobile").val("");
				
				$("#validateCode").val("");
				
				$("#password").val("");
				
				$("#tip_register").html("注册成功,正在登录...");
				
				//$(".ldh-loginBox").hide();	
				
				//exports.loginShow();
				
				$("#login_mobile").val(mobile);
				
				$("#login_password").val(password);
				
				
				exports.login();
				
			}else{
				
				$("#tip_register").html(data.message);
				
			}

			exports.cancelLoading("#btn_register");
			
			$("#btn_register").html("注册");
			
		}))().start();
		
	};
	

	//验证手机号是否注册过
	exports.validateMobile=function(inputId,btnId,tipId){
		
		var mobile = $(inputId).val();
		
		if(!validate.isMobile(mobile)){
			
			$(tipId).html("请填写正确的手机号码");
			
			return;
		}
		
		$(tipId).html("");
	
		$(btnId).attr("disabled", "disabled");

		exports.showLoading(btnId,20,true);
		
		if(btnId=="#btn_find_request_code"){
			
			sendMessage(mobile,btnId,tipId);
			
			return;
		}

		var params={
				"sign":MD5(mobile+"_sms_"),
				"mobile":mobile
			};
		
		eval(Wind.compile("async", function() {

			var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Reg/validateMobile.do", params));
			
			if(data.code == "1"){
				//未注册,发送验证码
				sendMessage(mobile,btnId,tipId);
			}else{
				
				$(tipId).html(data.message);
				
				$(btnId).html("免费获取验证码");
				
				//如果该手机已注册,则可以马上重新验证
				$(btnId).attr("disabled", false);
			}

		}))().start();
		
	};
	
	//发送短信验证码
	function sendMessage(mobile,btnId,tipId){
		
		var params={
				"sign":MD5(mobile+"_sms_"),
				"mobile":mobile
			};

		eval(Wind.compile("async", function() {

			var data;
			
			if(btnId=="#btn_find_request_code"){
				
				data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Login/sendValidateCode.do", params));

			}else{
				
				
				data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Reg/sendValidateCode.do", params));

			}
			
			
			if(data.code == "1"){
				
				task(btnId).start();
				
			}else{
				
				//如果获取验证码失败,则可以马上重新获取
				$(btnId).attr("disabled", false);
				
				$(btnId).html("免费获取验证码");
				
				$(tipId).html(data.message);
			
			}

		}))().start();
	}
	
	//倒计时
	var wait = 90;
	
	var tips_task = eval(Wind.compile("async", function (btnId) {
		wait--;
	    $await(Wind.Async.sleep(1000));
	    if(wait==0){
	    	//倒计时完成,发送验证码按钮生效
	    	$(btnId).attr("disabled", false);
	    	$(btnId).html("免费获取验证码");
	    	
	    }else{
	    	
	    	$(btnId).html(wait + "秒后重新获取");
	    }
	    
	}));
	
	var task = eval(Wind.compile("async", function (btnId) {
	    $await(tips_task(btnId));
	    if(wait>0){
	      task(btnId).start();
	    }else{
	    	wait=90;
	    }
	}));

	//找回密码框出现
	exports.forgotShow=function(){	
		$(".ldh-loginBox").show();
		var forgot_h=$("#ldh-forgot").outerHeight();
		$("#ldh-forgot").css("top",-forgot_h);
		$("#ldh-forgot").show().siblings(".ldh-loginDiv").hide();	
		$("#ldh-forgot").animate({top:230},300);	
		exports.forgotHide();	
	};
	
	//找回密码框消失
	exports.forgotHide=function(){
		$(document).on("click",".ldh-loginBox",function(event){
			var _target=$(event.target).parents();
			if(!_target.hasClass("ldh-loginBox")){
				var win_height=$(window).height();
				$("#ldh-forgot").animate({top:win_height},300);	
				setTimeout(function(){$(".ldh-loginBox").hide();$("#ldh-forgot").stop(true,true)},300);	
			}		
		})
	};
	
	//校验验证码是否正确
	exports.getValidate=function(){
		

		var mobile=$("#find_mobile").val();
		
		var validateCode=$("#find_validateCode").val();
		
		if(!validate.isMobile(mobile)){
			
			$("#tip_find").html("请填写正确的手机号码");
			
			return;
		}
		
		if(validate.isNull(validateCode)){
			
			$("#tip_find").html("请输入短信验证码");
			
			return;
		}
		
		
		exports.showLoading("#btn_find_next",22,true);

		$("#tip_find").html("");
		
		var params={
				"validatecode":validateCode,
				"mobile":mobile
			};

		eval(Wind.compile("async", function() {

			var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Login/getValidateCode.do", params));
			
			if(data.code == "1"){
				
				exports.changepwdShow();
				
				
				
			}else{
				
				$("#tip_find").html(data.message);
			
			}
			
			$("#btn_find_next").html("下一步");

		}))().start();
		
	};

	//修改密码框出现
	exports.changepwdShow=function(){
		$("#ldh-findpwd").animate({left:380},300);
		setTimeout(function(){
			$("#ldh-findpwd").hide();$("#ldh-findpwd").stop(true,true);
			$("#ldh-changepwd").css("left",-380);
			$("#ldh-changepwd").show();		
			$("#ldh-changepwd").animate({left:0},300);
			$(".ldh-pageTips span:eq(1)").addClass("on").siblings().removeClass("on");
		},300);	
			
	};
	
	//修改密码
	exports.reLoginPwd=function(){
		
		var find_password=$("#find_password").val();
		
		var find_confirm_password=$("#find_confirm_password").val();
		
		var mobile=$("#find_mobile").val();
		
	
		if(!validate.isLoginPassword(find_password)){
			
			$("#tip_re_pwd").html("密码必须为6-20位数字，字母，符号组合");
			
			return;
		}
		
		if(find_confirm_password!=find_password){
			
			$("#tip_re_pwd").html("两个密码必须一致");
			
			return;
		}
		
		$("#tip_re_pwd").html("");
		
		exports.showLoading("#btn_re_pwd",22,true);
		
		var params={
				"password":MD5(find_password),
				"mobile":mobile
			};

		eval(Wind.compile("async", function() {

			var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Login/reLoginPwd.do", params));
			
			if(data.code == "1"){
				
				$(".ldh-loginBox").hide();
				
				$("#find_password").val("");
				
				$("#find_confirm_password").val("");
				
				$("#find_mobile").val("");
				
				$("#find_validateCode").val("");
				
				
			}else{
				
				$("#tip_re_pwd").html(data.message);
			
			}
			

			$("#btn_re_pwd").html("确定");

		}))().start();
		
	};
	

	//关闭按钮
	exports.loginBoxClose=function(){
		$(".ldh-loginBox").click();	
	};
	

	//查询是否开店
	exports.getIsOpenShop=function(shopId){
		
		
		if(shopId==""){
			
			eval(Wind.compile("async", function() {

				var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Shop/getIsOpenShop.do", ""));
				
				if(data.code=="1"){
					
					if(data.shopId!=""){
			            
						
						exports.showBackStage();
						
						
					
					}else{
						
						exports.showOpenStore();
						
					}
				}else{
					
					exports.showOpenStore();

				}


			}))().start();
		}else{
			
			exports.showBackStage();

			
		}
		
	};
	
	//是否显示代理商后台
	exports.getIsShowAgent=function(_agentId){
	
		if(typeof(_agentId) == "undefined" || _agentId==""){
			$("#div_agent").html("");
		}else{
			$("#div_agent").html('<a href="'+ctx+'/admin/agent/index.jsp" target="_blank"><button type="button">代理商后台</button></a>');
		}
	};
	
	//显示"我要开店"
	exports.showOpenStore=function(){
		
		
				
		$("#div_store").html('<a href=javascript:$ldh_base.gotoOpenStore("openStore")><button type="button">我要开店</button></a>&nbsp;<span id="div_agent"></span>');
		
		//$("#div_store").html('');
		
		//$("#div_store").hide();
		
		exports.getIsShowAgent($("#session_agentId").val());
	};
	
	//显示"商家后台"
	exports.showBackStage=function(){
		
		$("#div_store").html('<a href="'+ctx+'/admin/index.jsp" target="_blank"><button type="button">商家后台</button></a>&nbsp;<span id="div_agent"></span>');
		
		$("#div_store").show();
		
		exports.getIsShowAgent($("#session_agentId").val());
	};
	
	//进入开店页面
	exports.gotoOpenStore=function(fun){
		
		
		//必须登录且没有开店的															
		if(exports.validateLoginStatusByUserId(fun) && validate.isNull($("#session_shopid").val())){
			
			
			window.location.href=ctx+"/v1/pages/store/openStore.jsp";
			
		}
		
		
	};
	
	//初始化搜索
	exports.initSearch=function(){
		
		var searchStr="",placeholder="",placeholder_merchansie="搜索附近商品",placeholder_shop="搜索附近店铺";
		searchStr += '<div class="selectbox">';
		
		if(validate.isNull($("#search_type").val()) || $("#search_type").val()=="1"){
			placeholder=placeholder_merchansie;
			searchStr += '<span class="selected" id="searchTypeName">商品</span>';
		}else{
			placeholder=placeholder_shop;
			searchStr += '<span class="selected" id="searchTypeName">商家</span>';
		}
		searchStr += '<ul>';
		searchStr += '<li><a href=javascript:$ldh_base.switchSearchType("1","商品","'+placeholder_merchansie+'")>商品</a></li>';
		searchStr += '<li><a href=javascript:$ldh_base.switchSearchType("2","店铺","'+placeholder_shop+'")>店铺</a></li>';
		searchStr += '</ul>';
		searchStr += '</div>';
		searchStr += '<form>';
		searchStr += '<input class="ts_txt" type="text" id="inputSearch" placeholder="'+placeholder+'" />';
		searchStr += '<input class="ts_btn" type="button" value="搜 索" onclick="$ldh_base.search()"/>';
		searchStr += '</form>';
		
		$("#div_search").html(searchStr);
		
	};
	
	//切换搜索类型
	exports.switchSearchType=function(type,typeName,placeholder){
		
		$("#search_type").val(type);
		
		$("#searchTypeName").html(typeName);
		
		$("#inputSearch").attr("placeholder",placeholder);
		
		$("#div_search").find("ul").hide();

		


	/*	//搜索商品、商家切换
		$(document).on("mouseover",".selectbox span",function(){
			$(this).parent().find("ul").show();
		})
		.on("mouseleave",".selectbox",function(){
			$(this).find("ul").hide();
		});*/
		
	};
	
	//搜索
	exports.search=function(){
		
		var inputSearch=$("#inputSearch").val();
		
		if(validate.isNull(inputSearch))
			return;
		
		if(validate.isNull($("#search_type").val()) || $("#search_type").val()=="1"){
			
			window.open(encodeURI(ctx+"/v1/pages/merchandise/merchandiseList.jsp?"+exports.encodeParams("keyword="+inputSearch)), "_blank");

		}else{
			
			if(document.URL.indexOf("shopList")>=0){
				
				window.location.href=encodeURI(ctx+"/v1/pages/shop/shopList.jsp?"+exports.encodeParams("keyword="+inputSearch));

			}else{
				
				window.open(encodeURI(ctx+"/v1/pages/shop/shopList.jsp?"+exports.encodeParams("keyword="+inputSearch)), "_blank");

			}

			
		}
		
	};

	
	
	// 获取特色
	exports.getSpeHtml=function(speId){
		
		var speHtml="";
		
		if(speId!="" && speId.indexOf(",")>0){
			var strArray=speId.split(",");
			
			for(var j=0;j<strArray.length;j++){
				
				speHtml+=getSpeItem(strArray[j]);
				
			}
		}else if(speId!=""){
			
			speHtml+=getSpeItem(speId);
		}
		
		if(speHtml=="")
			speHtml="暂无";
		
		return speHtml;
		
	};
	
	//获取一项特色
	function getSpeItem(type){
		
		if(type=="")
			return;
		
		var speHtml="";
		
		switch (parseInt(type)) {
		case 1:
			speHtml+='<i class="icon-fu" title="在线支付"></i>';
			break;
		case 2:
			speHtml+= '<i class="icon-xian" title="现金支付"></i>';
			break;
		case 3:
			speHtml+= '<i class="icon-shi" title="实体店"></i>';
			break;
		case 4:
			speHtml+= '<i class="icon-tao" title="淘宝店"></i>';
			break;
		case 5:
			speHtml+= '<i class="icon-v" title="营业执照"></i>';
			break;
		case 6:
			speHtml+= '<i class="icon-v2" title="卫生许可证"></i>';
			break;
		case 7:
			speHtml+= '<i class="icon-hui" title="有优惠"></i>';
			break;
		default:
			break;
		}
		
		return speHtml;
	}
	
	// 获取特色
	exports.getSpeListHtml=function(speId){
		
		var speHtml="";
		
		if(speId!="" && speId.indexOf(",")>0){
			var strArray=speId.split(",");
			
			for(var j=0;j<strArray.length;j++){
				
				speHtml+=getSpeItemList(strArray[j]);
				
			}
		}else if(speId!=""){
			
			speHtml+=getSpeItemList(speId);
		}
		
		if(speHtml=="")
			speHtml="暂无";
		
		return speHtml;
		
	};
	
	//获取一项特色
	function getSpeItemList(type){
		
		if(type=="")
			return;
		
		var speHtml="";
		
		switch (parseInt(type)) {
		case 1:
			speHtml+='<dd><i class="icon-fu"></i><span>支持在线支付</span></dd>';
			break;
		case 2:
			speHtml+= '<dd><i class="icon-xian"></i><span>支持现金支付</span></dd>';
			break;
		case 3:
			speHtml+= '<dd><i class="icon-shi"></i><span>实体店</span></dd>';
			break;
		case 4:
			speHtml+= '<dd><i class="icon-tao"></i><span>淘宝店</span></dd>';
			break;
		case 5:
			speHtml+= '<dd><i class="icon-v"></i><span>营业执照</span></dd>';
			break;
		case 6:
			speHtml+= '<dd><i class="icon-v2"></i><span>卫生许可证</span></dd>';
			break;
		case 7:
			speHtml+= '<dd><i class="icon-hui"></i><span>有优惠</span></dd>';
			break;
		default:
			break;
		}
		
		return speHtml;
	}
	
		
	//保存搜索历史
	exports.saveSearchHistoryCookie=function(name,lng,lat) {
		try {
			
			var cookieList;
			var cookie_item;
			
			if(validate.isNull(exports.getCookie("cookieList")) || typeof(exports.getCookie("cookieList"))=="undefined"){
				//如果历史记录为空,新家一条记录
				cookieList=new Array();
				cookie_item = new Object();
				cookie_item.name=name;
				cookie_item.lng=lng;
				cookie_item.lat=lat;
				cookieList.push(cookie_item);
				exports.setCookie("cookieList",JSON.stringify(cookieList));

				
			}else{
				
				
				var cookieListData=JSON.parse(exports.getCookie("cookieList"));
				
				cookieList=new Array();
				
				var isExits=false;
				
				for(var i=0;i<cookieListData.length;i++){
										
					if(name!=cookieListData[i].name){
						cookie_item = new Object();
						cookie_item.name=cookieListData[i].name;
						cookie_item.lng=cookieListData[i].lng;
						cookie_item.lat=cookieListData[i].lat;
						cookieList.push(cookie_item);
						
					}else{
						
						isExits=true;
					}
				}
				
				//如果历史记录不存在这条记录, 则把该记录添加进去
				if(!isExits){
					
					cookie_item = new Object();
					cookie_item.name=name;
					cookie_item.lng=lng;
					cookie_item.lat=lat;
					cookieList.push(cookie_item);
				}
				
				exports.setCookie("cookieList",JSON.stringify(cookieList));

				
			}
			
			

		} catch (e) {
		}
		
		exports.getSearchHistoryCookie();
	};
	
	//获取最近搜索列表
	exports.getSearchHistoryCookie=function() {
		
		try {

			
			if(!validate.isNull(exports.getCookie("cookieList"))){
				
				var cookieListData=JSON.parse(exports.getCookie("cookieList"));
				
				$("#historyList").html("");
				
				var length=cookieListData.length;
				
				if(length>10)
					length=10;
				
				for(var i=0;i<length;i++){
					
						var name=exports.replaceQuotationMarks(cookieListData[i].name);
						
						$("#historyList")
								.prepend(
										'<li onclick=$ldh_base.clickHistoryItem("'+name+'","'+cookieListData[i].lng+'","'+cookieListData[i].lat+'",event)><span   title="'
												+ name
												+ '">'
												+ exports.subString(name,9)
												+ '</span><i class="icon_close" onclick=$ldh_base.clearHisItemCookie("'
												+ name + '")>&nbsp;&nbsp;&nbsp;&nbsp;×</i></li>');
				}
				
			}
			

		} catch (e) {

		}

	};

	//点击历史记录
	exports.clickHistoryItem=function(address,lng,lat,event){
		
		/*
		var _target=$(obj).find("i");
	
		
		if(_target.hasClass("icon_close"))
			return;*/
		
		//var _target=$(event.target);
		var _target= event.srcElement ? $(event.srcElement):$(event.target);

		
		if(_target.hasClass("icon_close"))
			return;
		
		exports.setCookie("address",address);
		
		exports.setCookie("lng",lng);
		
		exports.setCookie("lat",lat);
		
		$("#address").html(exports.subString(exports.getCookie("address"),10));
		
		$("#address").attr("title",exports.getCookie("address"));
						
		if(exports.getFromPage()=="index"){
			
			$ldh_index.getShopListByType();
			
		}else if(exports.getFromPage()=="shopList"){
			
			$ldh_shop_list.getShopList();
			
		}
		
	};
	
	//清除某一个Cookies
	exports.clearHisItemCookie=function(name) {

		/*var _target=$(obj);
		
		if(!_target.hasClass("icon_close"))
			return;
		*/
		
		try {
			if(!validate.isNull(exports.getCookie("cookieList")) && typeof(exports.getCookie("cookieList"))!="undefined"){
				
					var cookieListData=JSON.parse(exports.getCookie("cookieList"));
					
					var cookieList=new Array();
					
					for(var i=0;i<cookieListData.length;i++){
						if(name!=cookieListData[i].name){
							var cookie_item = new Object();
							cookie_item.name=cookieListData[i].name;
							cookie_item.lng=cookieListData[i].lng;
							cookie_item.lat=cookieListData[i].lat;
							cookieList.push(cookie_item);
						}
					}
					exports.setCookie("cookieList",JSON.stringify(cookieList));

			}
			

		} catch (e) {

		}
		
		exports.getSearchHistoryCookie();

	};

	//清除Cookies
	exports.clearHisCookie=function() {
		exports.clearCookie("cookieList");
		$("#historyList").html("");
	};
	

	

	//选择地址层出现
	exports.myLocation=function(){
	
		$(".ldh-location").show();	
		
		$("#ldh-inputAdress").focus();
		
		exports.showCityPlaceholder();
		
		if(!validate.isNull(exports.getCookie("lng")) && !validate.isNull(exports.getCookie("lat"))){
			
			$("#btn_close_location").show();
		}else{
			$("#btn_close_location").hide();
		}
		
		//$(".ldh-location").fadeIn();
	};
	
	//选择地址层消失
	exports.myLocationHide=function(){
		$(".ldh-location").hide();	
		//$(".ldh-location").fadeOut();
		$("#inputSearch").focus();
	};
	
	
	//设置城市
	exports.setCity=function(cityId, cityName) {

		$("#cityName").html(cityName);

		exports.setCookie("cityId",cityId);
		
		exports.setCookie("cityName",cityName);
		
		$("#ldh-city").removeClass("on");
		
		exports.showCityPlaceholder();
	};
	
	//显示城市
	exports.showCity=function(){
		
		$("#ldh-city").addClass("on");
	};
	
	//切换城市提示
	exports.showCityPlaceholder=function(){
		
		var cityId=exports.getCookie("cityId");
		
		if(cityId=="440100"){
			
			$("#ldh-inputAdress").attr("placeholder","输入街道/地标/商圈.例如:广州塔");
			
			//$("#recommendAddress").html('<li><span>广州塔</span></li>');
			$(".ldh-banner").show();
		
		
			exports.initAd();
		
			
			
		}else if(cityId=="440400"){
			
			$("#ldh-inputAdress").attr("placeholder","输入街道/地标/商圈.例如:华发新城");
			
			//$("#recommendAddress").html('<li><span>华发新城</span></li>');
			
			$(".ldh-banner").hide();
			
		}else if(cityId=="110100"){
			
			$("#ldh-inputAdress").attr("placeholder","输入街道/地标/商圈.例如:朝阳大厦等");
			
			$(".ldh-banner").hide();
		}else if(cityId=="431300"){
			
			$("#ldh-inputAdress").attr("placeholder","输入街道/地标/商圈");
			
			$(".ldh-banner").hide();
		}
	};
	
	//广告显示和隐藏
	var initFlag=true;
	exports.initAd=function(){
		
		if(!initFlag){
			
			return;
		}
		
		initFlag=false;	
		
		var winWidth=940;
		$("#slide_01,.mod_01,.mod_01 img,.scroll").css("width",winWidth);
		if(document.getElementById("slide_01")){
			var slide_01 = new ScrollPic();
			slide_01.scrollContId   = "slide_01"; //内容容器ID
			slide_01.dotListId      = "slide_01_dot";//点列表ID
			slide_01.dotOnClassName = "selected";
			slide_01.arrLeftId      = "sl_left"; //左箭头ID
			slide_01.arrRightId     = "sl_right";//右箭头ID
			slide_01.frameWidth     = winWidth;
			slide_01.pageWidth      = winWidth;
			slide_01.upright        = false;
			slide_01.speed          = 40;
			slide_01.space          = 80;
			slide_01.autoPlayTime   = 3; //秒 
			slide_01.initialize(); //初始化
		}
		
	};
	
	//保存搜索的地址
	exports.setSearchAddress=function(address,lng,lat){
		
		exports.setCookie("address",address);
		
		exports.setCookie("lng",lng);
		
		exports.setCookie("lat",lat);
		
		$("#address").html(exports.subString(exports.getCookie("address"),10));
		
		$("#address").attr("title",exports.getCookie("address"));
		
		exports.myLocationHide();
		
		exports.saveSearchHistoryCookie(address,lng,lat);
		
		if(exports.getFromPage()=="index"){
			
			$ldh_index.getShopListByType();
			
		}else if(exports.getFromPage()=="shopList"){
			
			$ldh_shop_list.getShopList();
			
		}
		
	};
	
	//选择搜索出来的地址
	exports.selectSearchItem=function(title,lng,lat){

		$("#ldh-inputAdress").val(title);
		
		$(".ldh-addressGroup").hide();
		
		exports.setSearchAddress(title,lng,lat);
		
	};
	
	
	
	//输入地址栏
	exports.inputAdress=function(){  
		var inpVal=$("#ldh-inputAdress").val();
		var inpAd=$("#ldh-inputAdress");		
		inpAd.focus(function(){focusE()});	
		function focusE(){
			hideAd();
			$(document).on("mouseover",".ldh-addressGroup li",function(){
				$(this).addClass("on").siblings().removeClass("on")
				}).on("click",".ldh-addressGroup li",function(){
					inpAd.val($(this).html());inpVal=inpAd.val();/*inpAd.blur()*/
				});				
			$(document).on("keydown",function(event){
					var lilenght=$(".ldh-addressGroup li").length-1;
					var indexOn=$(".ldh-addressGroup li.on").index();		
					event=window.event||event;
					var currkey=event.keyCode||event.which||event.charCode;			
					if((currkey!=13)&&(currkey!=38)&&(currkey!=40)){$(document).keyup(function(){
						inpVal=inpAd.val();
						if (inpVal != "") {
							localSearch.search($("#cityName").html() + inpVal);
						}
						$(document).off("keyup")
					})}
					//向上箭头
					if(currkey==38){
						
						if(!$(".ldh-addressGroup").is(":visible"))
							return;
						
						if(indexOn>0){
							indexOn--;
							var On=$(".ldh-addressGroup li:eq("+indexOn+")");
							On.addClass("on").siblings().removeClass("on");
							inpAd.val(On.html());
						}else if(indexOn==0){
							indexOn--;
							$(".ldh-addressGroup li").removeClass("on");
							inpAd.val(inpVal);
						}else{
							indexOn=lilenght;
							var On=$(".ldh-addressGroup li:eq("+indexOn+")");
							On.addClass("on").siblings().removeClass("on");
							inpAd.val(On.html());
						}	
						
					}
					//向下箭头
					if(currkey==40){
						
						if(!$(".ldh-addressGroup").is(":visible"))
							return;
						
						if(lilenght>indexOn){
							indexOn++;
							var On=$(".ldh-addressGroup li:eq("+indexOn+")");
							On.addClass("on").siblings().removeClass("on");
							inpAd.val(On.html());
						}else if(lilenght==indexOn){
							indexOn++;$(".ldh-addressGroup li").removeClass("on");
							inpAd.val(inpVal);
						}else{
							indexOn=0;var On=$(".ldh-addressGroup li:eq("+indexOn+")");
							On.addClass("on").siblings().removeClass("on");
							inpAd.val(On.html());
						}	
						
					}
					//回车
					if(currkey==13){
						
						if(!$(".ldh-addressGroup").is(":visible"))
							return;
						
						inpVal=inpAd.val();
						/*inpAd.blur()*/;
						$(".ldh-addressGroup").hide();		
						
						if(validate.isNull($(".ldh-addressGroup li:eq("+indexOn+")").attr("lng")) || validate.isNull($(".ldh-addressGroup li:eq("+indexOn+")").attr("lat"))){
							
							return;
						}
						
						exports.setSearchAddress(inpAd.val(),$(".ldh-addressGroup li:eq("+indexOn+")").attr("lng"),$(".ldh-addressGroup li:eq("+indexOn+")").attr("lat"));
					}
					
					
				
					/*function getLngAndLat(val){
						
						$("#inputAdress").val(val);
						
						var options = {
								onSearchComplete: function(results){
									// 判断状态是否正确
									if (local.getStatus() == BMAP_STATUS_SUCCESS){
										
											 var poi = results.getPoi(0);
											 
											 $(document).click()
											 
											searchShop(val,poi.point.lng,poi.point.lat);
									}
								}
							};

						var local = new BMap.LocalSearch(map, options);
						
						local.search(val);
						
						
					}*/
			});
			
		}
		function blurE(){
		
			$(document).off("keydown");	
			inpAd.val(inpVal);
			$(".ldh-addressGroup").hide();
			//exports.setSearchAddress(inpAd.val());
		}
		function hideAd(){
			
			$(document).one("click", function(){blurE();inpAd.blur()});
			$(".ldh-addressInput").click(function(event){event.stopPropagation()})
		
		}
	};
	
	//初始化百度地图
	var localSearch="";
	exports.initMap=function(){
		
		var map = new BMap.Map("l-map");
		
		var options = {
				onSearchComplete: function(results){
					// 判断状态是否正确
					if (localSearch.getStatus() == BMAP_STATUS_SUCCESS){
						
						$("#searchLResultList").html("");
						
						for (var i = 0; i < results.getCurrentNumPois(); i ++){
							 var poi = results.getPoi(i);
							 var title=exports.replaceQuotationMarks(results.getPoi(i).title);
							
							$("#searchLResultList").append('<li lat="'+poi.point.lat+'" lng="'+poi.point.lng+'" onclick=$ldh_base.selectSearchItem("'+title+'","'+poi.point.lng+'","'+poi.point.lat+'")>'+results.getPoi(i).title+'</li>');
						}
						
						//(<font color=#CCCCCC>'+results.getPoi(i).address+'</font>)
						
						if(results.getCurrentNumPois()>0){

							$(".ldh-addressGroup").show();
						}
					}
				}
			};

		localSearch = new BMap.LocalSearch(map, options);
		
		
	};
	

	//跳转到商家主页
	exports.jumpToShopIndex=function(shopId){
		
		//get2post(ctx+"/v1/pages/shop/shopIndex.jsp?shopId="+shopId,"_blank");
		
		window.open(encodeURI(ctx+"/v1/pages/shop/shopIndex.jsp?"+exports.encodeParams("shopId="+shopId)),"_blank");
		
	};
	
	//跳转到商家列表
	exports.jumpToShopList=function(shopTypeId){
		
		//get2post(ctx+"/v1/pages/shop/shopList.jsp?shopTypeId="+shopTypeId,"_blank");
		window.open(encodeURI(ctx+"/v1/pages/shop/shopList.jsp?"+exports.encodeParams("shopTypeId="+shopTypeId)),"_blank");
	
	};
	
	//批量替换
	String.prototype.replaceAll  = function(oldString,newString){     
	    return this.replace(new RegExp(oldString,"gm"),newString);     
	};
	
	//参数加密
	exports.encodeParams=function(params){
		
		if(validate.isNull(params))
			return;
		
		params="#"+params.toString()+"#";
		
		var length=params.length;
		
		
		if(length<5){
			params+="##%%#%";
			length+=6;
		}
		var str="";
		
		for(var i=0;i<length;i++){
			if(i%2==0){
				str+=params.substring(i,i+1)+"#";
			}else{
				
				str+=params.substring(i,i+1)+"%";
			}
			
		}
		return escape(str);
			
	};
	
	//参数解密
	exports.decodeParams=function(params){
		
		params=unescape(params);
		
		params=params.replaceAll("#","");
		
		params=params.replaceAll("%","");
		
		return params;
	};
	
	//四舍五入
	exports.Digit=function(digit, length) {
	    length = length ? parseInt(length) : 0;
	    if (length <= 0) return Math.round(digit);
	    digit = Math.round(digit * Math.pow(10, length)) / Math.pow(10, length);
	    return digit;
	};
	
});